package com.atguigu.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.atguigu.bean.DruidBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-01-15
 * @Description:
 * @Version: 1.0
 */
@Configuration
@ComponentScan("com.atguigu")
public class DruidConfig {
    /*@Value("${jdbc.driverClassName}")
    private String driverClassName;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;*/
    @Autowired
    @Qualifier("jdbcProperties")
    private DruidBean druidBean;


    @Bean("druidDataSource")
    public DruidDataSource druidDataSource(DruidBean jdbcProperties) {
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(jdbcProperties.getDriverClassName());
        druidDataSource.setUrl(jdbcProperties.getUrl());
        druidDataSource.setUsername(jdbcProperties.getUsername());
        druidDataSource.setPassword(jdbcProperties.getPassword());
        return druidDataSource;
    }


}
